package app

import (
	"github.com/gin-gonic/gin"
	"hc_server/runtime/e"
	"net/http"
)

type Gin struct {
	C *gin.Context
}

type Response struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

type LoginResponse struct {
	Code  int         `json:"code"`
	Msg   string      `json:"msg"`
	Data  interface{} `json:"data"`
	Token string      `json:"token"`
}

type PageResponse struct {
	Code  int         `json:"code"`
	Msg   string      `json:"msg"`
	Data  interface{} `json:"data"`
	Total string      `json:"total"`
}

func (g *Gin) ResponseSuccess(msg string, data interface{}) {
	g.C.JSON(http.StatusOK, Response{
		Code: e.SUCCESS,
		Msg:  msg,
		Data: data,
	})
	return
}

func (g *Gin) ResponseError(msg string, data interface{}) {
	g.C.JSON(http.StatusOK, Response{
		Code: e.ERROR,
		Msg:  msg,
		Data: data,
	})
	return
}

func (g *Gin) ResponsePageSuccess(msg string, data interface{}, total string) {
	g.C.JSON(http.StatusOK, PageResponse{
		Code:  e.SUCCESS,
		Msg:   msg,
		Data:  data,
		Total: total,
	})
	return
}

func (g *Gin) ResponseLoginSuccess(msg string, data interface{}, token string) {
	g.C.JSON(http.StatusOK, LoginResponse{
		Code:  e.SUCCESS,
		Msg:   msg,
		Data:  data,
		Token: token,
	})
	return
}
